package com.whitedust.top90;

import java.util.Arrays;

/**
 *
 * @author A
 * @since 2025/11/16 14:43
 */

public class Top83 {
    public String largestNumber(int[] nums) {
        String[] sNums = new String[nums.length];
        for (int i = 0; i < nums.length; i++) {
            sNums[i] = String.valueOf(nums[i]);
        }
        Arrays.sort(sNums,(a,b)->{
            String ab = a+b;
            String ba = b+a;
            return ab.compareTo(ba);
        });
        StringBuilder sb = new StringBuilder();
        for (int i =sNums.length-1;i>=0;i--) {
            sb.append(sNums[i]);
        }
        //有多个0的情况，应该要去除
        int len = sb.length();
        int k = 0;
        while (k < len - 1 && sb.charAt(k) == '0') k++;
        return sb.substring(k);
    }
}
